package com.cyw.email.service;

import cn.hutool.Hutool;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cyw.email.entity.DayEntity;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Chenyw
 * @Date: 2022/08/23/23:45
 */


public class DayService {

    public static DayEntity getDay(){
        String url = "https://restapi.amap.com/v3/weather/weatherInfo";
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("key","7a2411eba6be444a979db71664f818a6");
        paramMap.put("city","110114");

        JSONObject jsonObject = JSON.parseObject(HttpUtil.get(url, paramMap));
        JSONArray lives = jsonObject.getJSONArray("lives");

        String str = lives.get(0).toString();
        DayEntity dayEntity = JSON.parseObject(str, DayEntity.class);
        //get请求有参
        return dayEntity;

    }
}
